<?php
	if(!isset($_SESSION)){
    	session_start();
	}
	include_once("../class/config.class.php"); 
	$config = config::getConfig();
	include_once($config->getValue("home_path")."/inc/defines.inc.php");

	include_once(HOME_PATH."/class/form.class.php");
	include_once(HOME_PATH."/class/database.class.php");
	include_once(HOME_PATH."/class/user.class.php");
	
	$oUser = new user($config);
	$oDB = new database($config);
	$oUser->setDB($oDB);
	
	if(!isset($_SESSION['is_admin']) || $_SESSION['is_admin']!==true){
		if(isset($_POST['pass']) && $_POST['pass']!==""){
			//Kontrollieren ob das korrekte Passwort eingegeben wurde
			if(!$oUser->isAdminPass($_POST['pass'])){
				Header("Location: admin.php"); 			
			}
		}	
		// Loginform einbinden
		include(HOME_PATH."/templates/header.tpl.php");
		include(HOME_PATH."/templates/admin/admin_login.tpl.php");
	}else{
		if(isset($_POST['teachName']) && $_POST['teachName']!==""){
			$vTemp = $oUser->addNewTeacher($_POST['teachName']);
			if($vTemp==-1){
				$sError = "Name wird bereits verwendet!";
			}
		}
		$aTeachers = $oUser->getTeacherList();		
		include(HOME_PATH."/templates/header.tpl.php");
		include(HOME_PATH."/templates/admin/newTeacher.tpl.php");
		echo "<table>";
		for($i=0; $i<count($aTeachers); $i++){
			$sPass = $oUser->getTeacherPass($aTeachers[$i]['name']);			
			include(HOME_PATH."/templates/admin/teacherList.tpl.php");
		}
		echo "</table>";
	}
	include(HOME_PATH."/templates/footer.tpl.php");
?>